﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo04_重写Paint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = this.CreateGraphics();
            //g = e.Graphics;   可以直接使用
            Pen p = new Pen(Color.Red,5);
            g.DrawEllipse(p, 120, 60, 150, 150);
            p.Dispose();
            g.Dispose();
        }

        /// <summary>
        /// 在按钮上绘制文字
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.DrawString("画中画123", new Font("隶书", 12), Brushes.Red, new Point(16, 8));
        }
    }
}
